#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QPushButton>
#include<QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    connect(ui->switch_button,&QPushButton::clicked,this,&MainWindow::openChartWindow);

    st=new sensor_thread();
    st->start();
}


MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::openChartWindow()
{
    chartWindow=new QWidget();
    chartWindow->setWindowTitle("图表窗口");
    chartWindow->resize(800,600);

    Graph=new Chart(chartWindow);
    Graph->sensor=&st->sensor;
    Graph->position=&st->position;
    QVBoxLayout *layout=new QVBoxLayout(chartWindow);
    layout->addWidget(Graph);
    chartWindow->setLayout(layout);

    updateTimer=new QTimer(this);
    connect(updateTimer,&QTimer::timeout,Graph,&Chart::updateChart);
    updateTimer->start(100);

    chartWindow->show();
}
